//1652.拆炸弹
//https://leetcode.cn/problems/defuse-the-bomb/
class Solution {
public:
    vector<int> decrypt(vector<int>& code, int k) {
        int n = code.size();
        vector<int> ret;
        ret.reserve(n);
        if(k == 0) ret.resize(n,0);
        else if(k > 0)
        {
            for(int i = 0;i<n;++i)
            {
                int num = 0;
                for(int t = 0,j = i+1;t<k;++t,++j) num += code[j%n];
                ret.push_back(num);
            }
        }
        else
        {
            k = -k;
            for(int i = 0;i<n;++i)
            {
                int num = 0;
                for(int t = 0,j = i-1;t<k;++t,--j) 
                {
                    if(j < 0) j = n-1;
                    num += code[j%n];
                    if(j == 0) j = n;
                }
                ret.push_back(num);
            }
        }

        return ret;
    }
};